import Taro from '@tarojs/taro';
import * as sdk from './fetch';

/**
 *
 * 获取会员基本信息
 *
 */
async function getMemberBase(request: IGetSignRequestReq = {}): Promise<TicketResponse> {
  let result = await sdk.get<TicketResponse>('/customer/customerBase', {
    ...request,
  });
  // 此处暂时是无用缓存
  // Taro.setStorageSync('memberBase', {
  //   customerDetail: result.context,
  // });
  return result.context;
}

async function setIplandMemberBase(params:Record<string,any>){
  let result = await sdk.put<TicketResponse>('/gamecustomerinfo/modify', {
    ...params,
  });
  // 此处暂时是无用缓存
  // Taro.setStorageSync('memberBase', {
  //   customerDetail: result.context,
  // });
  return result.context;
}
async function getMemberEquityNum(request: IGetSignRequestReq = {}, login: boolean): Promise<TicketResponse> {
  // let result = await sdk.get<TicketResponse>(
  //   `/levelRights/customerRightsList${login ? '' : `2/${Taro.getStorageSync('storeId')}`}`,
  //   {},
  // );
  // return result.context;

  const data = {
    ...request,
  };

  console.log(data);
  let result = await sdk.get<TicketResponse>(
    `/levelRights/customerRightsList${login ? '' : `2/${Taro.getStorageSync('storeId')}`}`,
    data,
  );
  return result.context;
}

async function getMemberEquityNum2(memberType: number, enterWay: number): Promise<TicketResponse> {
  let result = await sdk.post<TicketResponse>(`/twocategory/count`, {
    memberType,
    enterWay,
  });
  return result.context;
}

async function getLotteryButtonShow(request = {}) {
  let result = await sdk.post<TicketResponse>('/turntableactivity/whetherActivity', {
    ...request,
  });
  return result.context;
}

async function getIplandMemberBase(request: IGetSignRequestReq = {}): Promise<TicketResponse> {
  let result = await sdk.get<TicketResponse>('/gamecustomerinfo', {
    ...request,
  });

  return result.context;
}


export default {
  getMemberBase,
  getLotteryButtonShow,
  getMemberEquityNum,
  getMemberEquityNum2,
  getIplandMemberBase,
  setIplandMemberBase,
};

/**
 * 内容
 */
export interface TicketResponse {
  /**
   * appId
   */
  appId?: string;
  /**
   * 字符串
   */
  nonceStr?: string;
  /**
   * 加密信息
   */
  signature?: string;
  /**
   * 时间戳
   */
  timestamp?: string;
  /**
   * url
   */
  url?: string;
  [k: string]: any;
}

/**
 * This interface was referenced by `IgnoreType`'s JSON-Schema
 * via the `definition` "IGetSignRequestReq".
 */
export interface IGetSignRequestReq {
  url?: string;
  [k: string]: any;
}

//create by moon https://github.com/creasy2010/moon
